﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Project.Ycm20250401.Service._20250407
{
   /// <summary>
   /// 工厂类，根据传入的策略列表，返回对应的策略实例
   /// </summary>
   /// <param name="strategies"></param>
    public class PriceStrategyFactory(IEnumerable<IPriceStrategy> strategies)
    {
        public IPriceStrategy GetStrategy(ActivityType type)
            => strategies.FirstOrDefault(s => s.IsMatch(type))
               ?? throw new UnsupportedActivityException(type);
    }
    /// <summary>
    /// 异常类，表示不支持的活动类型
    /// </summary>
    /// <param name="type"></param>
    public class UnsupportedActivityException(ActivityType type)
        : Exception($"Unsupported activity type: {type}");

}
